/**
 * 参数设置管理初始化
 */
var PartnerApply = {
    id: "PartnerApplyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
PartnerApply.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle',width:'50px'},
        {title: '状态', field: 'zhuangtai', align: 'center', valign: 'middle'},
        {title: '申请时间', field: 'applyTime', align: 'center',sortable: true, valign: 'middle'},
        {title: '姓名', field: 'userName', align: 'center', valign: 'middle'},
        {title: '绑定手机', field: 'bindingPhone', align: 'center', valign: 'middle'},
        {title: '身份证号码', field: 'idNo', align: 'center', valign: 'middle'},
        {title: '推荐人推荐码', field: 'recommendationNo', align: 'center', valign: 'middle'},
        {title: '矿机数量', field: 'robNum', align: 'center', valign: 'middle'},
        {title: '应付金额', field: 'payableAmount', align: 'center', valign: 'middle'},
        {title: '支付方式', field: 'zhifufangshi', align: 'center', valign: 'middle'},
        {title: '支付渠道', field: 'payChannel', align: 'center', valign: 'middle'},
        {title: '缴费流水号', field: 'flowNo', align: 'center', valign: 'middle'},
        {title: '实付金额', field: 'payMoney', align: 'center', valign: 'middle'},
        {title: '支付时间', field: 'payTime', align: 'center', valign: 'middle'},
        {title: '审核时间', field: 'examineTime', align: 'center', valign: 'middle'}
    ]
    return columns;
};

/**
 * 检查是否选中
 */
PartnerApply.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        PartnerApply.seItem = selected[0];
        return true;
    }
};

/**
 * 检查是否可以进行跟单
 */
PartnerApply.checkfollow = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    PartnerApply.seItem = selected[0];
    if(PartnerApply.seItem.zhuangtai != "待签约"){
        Feng.info("这条申请不能执行这项操作！");
        return false;
    }else{
        return true;
    }
};

/**
 * 检查是否可以进行跟单
 */
PartnerApply.checkedit = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    PartnerApply.seItem = selected[0];
    if(PartnerApply.seItem.zhuangtai == "已审核"){
        Feng.info("已审核的记录不能修改！");
        return false;
    }else{
        return true;
    }
};

/**
 * 检查是否可以进行签约操作
 */
PartnerApply.checksign = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    PartnerApply.seItem = selected[0];
    if(PartnerApply.seItem.zhuangtai == "已审核"){
        Feng.info("这个申请已经审核完成！");
        return false;
    }else{
        return true;
    }
};

/**
 * 点击添加合伙人
 */
PartnerApply.PartnerApplyAdd = function () {

    var index = layer.open({
        type: 2,
        title: '手动新增合伙人',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/partnerApply/partnerApply_add'
    });
    this.layerIndex = index;
};

/**
 * 修改
 */
PartnerApply.PartnerApplyUpdate = function () {

    if (this.check()) {
        if(this.checkedit()) {
            var index = layer.open({
                type: 2,
                title: '修改',
                area: ['800px', '420px'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/partnerApply/partnerApply_update/' + PartnerApply.seItem.id
            });
            this.layerIndex = index;
        }
    }
};

/**
 * 跟单
 */
PartnerApply.PartnerApplyFollow = function () {
    if (this.check()) {
         if(this.checkfollow()) {
             var index = layer.open({
                 type: 2,
                 title: '跟单',
                 area: ['800px', '420px'], //宽高
                 fix: false, //不固定
                 maxmin: true,
                 content: Feng.ctxPath + '/partnerApply/partnerApply_follow/' + PartnerApply.seItem.id
             });
             this.layerIndex = index;
         }
    }
};

/**
 * 签约
 */
PartnerApply.PartnerApplySign = function () {
    if (this.check()) {
        if(this.checksign()) {
            var index = layer.open({
                type: 2,
                title: '签约',
                area: ['800px', '420px'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/partnerApply/partnerApply_sign/' + PartnerApply.seItem.id
            });
            this.layerIndex = index;
        }
    }
};


/**
 *收件信息
 */
PartnerApply.PartnerApplyExp = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '收件信息',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/partnerApply/partnerApply_exp/' + PartnerApply.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除参数设置
 */
PartnerApply.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/partnerApply/del", function (data) {
            Feng.success("删除成功!");
            PartnerList.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询参数设置列表
 */
PartnerApply.search = function () {
    var queryData = {};
    //queryData['name'] = $("#name").val();
    queryData['bindingPhone'] = $("#bindingPhone").val();
    //queryData['contract_no'] = $("#contract_no").val();
    queryData['disUsername'] = $("#disUsername").val();
    queryData['status'] = $("#status").val();
    queryData['applytime'] = $("#applytime").val().replace("/","-");
    if($("#applytime").val() != "") {
        if($("#applytime_end").val() == "") {
            Feng.info("请选择结束时间！");
            return false;
        }else{
            queryData['applytime_end'] = $("#applytime_end").val().replace("/","-");
        }
    }
    PartnerApply.table.refresh({query: queryData});
};

$(function () {

    $("#applytime").attr('type','date');
    $("#applytime_end").attr('type','date');
    var defaultColunms = PartnerApply.initColumn();
    var table = new BSTable(PartnerApply.id, "/partnerApply/list", defaultColunms);
    table.setPaginationType("client");
    PartnerApply.table = table.init();
});
